import 'package:demo/routers/navigators.dart';
import 'package:flutter/material.dart';

const List<String> singleLayoutWidgets = [
  "Container",
  "Padding",
  "Center",
  "Align",
  "FittedBox",
  "AspectRatio",
  "ConstrainedBox",
  "Baseline",
  "FractionallySizedBox",
  "IntrinsicHeight",
  "IntrinsicWidth",
  "LimitedBox",
  "Offstage",
  "OverflowBox",
  "SizedBox",
  "SizedOverflowBox",
  "Transform",
  "CustomSingleChildLayout",
];

const List<String> multiLayoutWidgets = [
  "Row",
  "Column",
  "Stack",
  "IndexedStack",
  "GridView",
  "Flow",
  "Table",
  "Wrap",
  "ListBody",
  "ListView",
  "CustomMultiChildLayout",
];

class DisplayPage extends StatefulWidget {
  DisplayPage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _DisplayPageState createState() => new _DisplayPageState();
}

void _navigateToPage(BuildContext context, String page) {
  print("Page:$page");
  Navigators.push(context, '/$page');
}

class _DisplayPageState extends State<DisplayPage> {
  @override
  Widget build(BuildContext context) {
    List<String> layoutWidgets = [];
    layoutWidgets.add("-- Single-child layout widgets --");
    layoutWidgets.addAll(singleLayoutWidgets);
    layoutWidgets.add("-- Multi-child layout widgets --");
    layoutWidgets.addAll(multiLayoutWidgets);

    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Flutter Widgets'),
        elevation: 1,
      ),

      body: new ListView.builder(
        itemBuilder: (BuildContext buildContext, int index) {
          return Column(
            children: <Widget>[
              new ListTile(
                title: new LayoutListItem(
                  index: index,
                  title: layoutWidgets[index],
                  onPress: () {
                    String item = layoutWidgets[index];
                    if (item.startsWith("--")) {
                      return;
                    }
                    _navigateToPage(context, layoutWidgets[index]);
                  },
                ),
              ),
              new Divider(),
            ],
          );
        },
        itemCount: (singleLayoutWidgets.length + multiLayoutWidgets.length + 2),
      ),
    );
  }
}

class LayoutListItem extends StatelessWidget {
  LayoutListItem({this.index, this.title, this.onPress});

  final int index;
  final String title;
  final VoidCallback onPress;

  @override
  Widget build(BuildContext context) {
    return new GestureDetector(
      onTap: onPress,
      child: new Center(
        child: new Text(
          "$title",
          style: new TextStyle(fontSize: 16.0, color: Colors.black),
        ),
      ),
    );
  }
}
